<template>
  <div class="add-common-user">
    <nav-top title="添加预约用户" :goback="true"></nav-top>
    <div class="form">
      <van-field
        class="input"
        v-model="currentMsg.fullName"
        label-width="4.687rem"
        placeholder="请输入姓名"
      >
        <span class="input-label" slot="label">姓名(中文)*</span>
      </van-field>
      <van-field
        class="input"
        v-model="currentMsg.surname"
        label-width="4.687rem"
        placeholder="请输入姓(拼音)"
      >
        <span class="input-label" slot="label">姓(拼音)*</span>
      </van-field>
      <van-field
        class="input"
        v-model="currentMsg.name"
        label-width="4.687rem"
        placeholder="请输入名(拼音)"
      >
        <span class="input-label" slot="label">名(拼音)*</span>
      </van-field>
      <van-field
        class="input input-select"
        v-model="currentMsg.certificateType"
        label-width="4.687rem"
        placeholder="请选择证件类型"
        readonly
        @click="showSelect=true"
      >
        <span class="input-label" slot="label">证件类型*</span>
      </van-field>
      <van-popup position="bottom"
               v-model="showSelect">
        <van-picker show-toolbar
                  :columns="columns"
                  cancel-button-text=' '
                  @confirm="onConfirm" />
      </van-popup>
      <van-field
        class="input"
        v-model="currentMsg.certificate"
        label-width="4.687rem"
        placeholder="请输入证件号"
      >
        <span class="input-label" slot="label">证件号*</span>
      </van-field>
      <div class="select">
        <span class="input-label" slot="label">性别*</span>
        <van-radio-group class="radio" v-model="currentMsg.radio">
          <van-radio class="radio-item" name="1">
            <span class="radio-title" slot="default">男</span>
            <img
              class="radio-icon"
              slot="icon"
              slot-scope="props"
              :src="props.checked ? '/static/icon/select-select.png' : '/static/icon/select-none.png'"
            />
          </van-radio>
          <van-radio class="radio-item" name="2">
            <span class="radio-title" slot="default">女</span>
            <img
              class="radio-icon"
              slot="icon"
              slot-scope="props"
              :src="props.checked ? '/static/icon/select-select.png' : '/static/icon/select-none.png'"
            />
          </van-radio>
          <!-- <van-radio checked-color="#07c160" name="2">女</van-radio> -->
        </van-radio-group>
      </div>
      <van-field
        class="input"
        v-model="currentMsg.phone"
        label-width="4.687rem"
        type="tel"
        placeholder="请输入手机号"
      >
        <span class="input-label" slot="label">手机号码*</span>
      </van-field>
      <van-field
        class="input"
        v-model="currentMsg.wxcode"
        label-width="4.687rem"
        placeholder="请输入微信号"
      >
        <span class="input-label" slot="label">微信号</span>
      </van-field>
    </div>

    <van-button class="submit" @click="sub" type="primary" size="large">提交</van-button>
  </div>
</template>

<script>
import NavTop from "@/components/nav/navBar";
import axios from 'axios'
import { domain, search } from './../../api'
export default {
  name: "AddCommonUser",
  components: {
    NavTop
  },
  created(){
    
  },
  data() {
    return {
      showSelect: false,
      columns: ['护照', '港澳通行证'],
      currentMsg: {
      }
    };
  },
  methods: {
    sub(){
      if(this.currentMsg.radio == "1"){
        this.currentMsg.radio = 1 // nan
      }else{
        this.currentMsg.radio = 2 // nv
      }
      console.log(this.currentMsg.fullName)
      if( this.currentMsg.fullName != undefined && this.currentMsg.fullName != undefined && this.currentMsg.phone != undefined && this.currentMsg.surname != undefined && this.currentMsg.name != undefined && this.currentMsg.certificateType != undefined && this.currentMsg.certificate != undefined){
        let data = {
          name: this.currentMsg.fullName,
          sex: this.currentMsg.radio,
          tel: this.currentMsg.phone,
          name_py: this.currentMsg.surname,
          class_name: this.currentMsg.name,
          card_class: this.currentMsg.certificateType,
          card: this.currentMsg.certificate,
          wechat: this.currentMsg.wxcode
        }
        axios.post(domain+'/api/old/userinfo', data)
        .then((res)=>{
          if(res.data.code==1){
            // 提交成功 跳转到选择页面
            window.location.href = "/product/order/select/user"+window.location.search
          }else{
            this.$dialog.alert({
              title: '发生错误',
              message: res.data.err
            })
          }
        })
        .catch((err)=>{
          this.$dialog.alert({
            title: '发生错误',
            message: err
          })
        })
      }else{
        this.$dialog.alert({
            title: '输入错误',
            message: '所有带有“*”的必须输入'
          })
      }
      
    },
    onConfirm (val) {
      this.currentMsg.certificateType = val;
      this.showSelect = false;
    }
  }
};
</script>
<style lang='scss' scoped>
.add-common-user {
  overflow: hidden;
  overflow-y: auto;
  height: 690px;
  background-color: #f8f8f8;
  .form {
    background-color: #ffffff;
    margin-top: 46px;
    padding-left: 13px;
    padding-right: 13px;
    .select {
      height: 38px;
      border-bottom: 1px solid #ececec;
      .input-label {
        float: left;
        line-height: 41px;
        font-size: 13px;
        line-height: 20px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        margin-top: 12px;
      }
      .radio {
        position: relative;
        top: 6px;
        left: 170px;
        .radio-item {
          float: left;
          .radio-title {
            font-size: 11px;
            line-height: 1em;
          }
          .radio-icon {
            position: relative;
            top: 4px;
            left: 8px;
            width: 16px;
            height: 15px;
          }
        }
      }
    }
    .input {
      position: relative;
      padding: 0px;
      padding-top: 9px;
      padding-bottom: 9px;
      border-bottom: 1px solid #ececec;
      font-size: 13px;
      line-height: 20px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      .input-label {
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: rgba(0, 0, 0, 1);
      }
      ::-webkit-input-placeholder {
        color: rgba(214, 214, 214, 1);
      }
      .send-code {
        height: 16px;
        line-height: 1px;
        font-size: 12px;
        background: #fff;
        color: #4d39c6;
        border: none;
      }
    }
  }
  .submit {
    width: 279px;
    height: 44px;
    margin: 83px 20.5px 0 20.5px;
    // position: absolute;
    // left: 21px;
    // bottom: 15px;
    font-size: 15px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    background: #06a44f;
    border: none;
  }
}
.van-radio__icon {
  width: 15px !important;
  height: 15px !important;
  .van-icon {
    width: 15px !important;
    height: 15px !important;
  }
}
</style>
